C Interview Questions And Answers

adplus-dvertising
C FAQS
Previous Home Next

C,C++ Questions with answers, C++ Questions Interview with answers

C,C++ Questions

Questions 11. In the question 10 an array of pointers is declared.
    Write the statement to initialize the 3rd element of the 2 element to 10;

Questions 12.
int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}

What are the number of syntax errors in the above?

Ans: None.

Questions 13.
void main()
{
int i=7;
printf("%d",i++*i++);
}

Ans: 56

Questions 14.
#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");

Ans: "one is defined"

Questions 15.
void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}

Ans: 20 20 20

Questions 16. what is alloca()
Ans : It allocates and frees memory after use/after getting out of scope

Questions 17.
main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}

Ans: 321

Questions 18.
char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}

Ans: anything is good.

Questions 19.
void main()
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s",++*p);
printf("%s",*p++);
printf("%s",++*p);
}
Ans: "harma" (p->add(dharma) && (*p)->harma)
"harma" (after printing, p->add(hewlett-packard) &&(*p)->harma)
"ewlett-packard"

Questions 20. Output of the following program is
main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
e) Syntax error
Ans. (d)

Previous Home Next